namespace CISLib
{
    using System;
    using System.Security.Principal;

    public class UserPrincipal : IPrincipal
    {
        private IIdentity _Identity = null;
        private Area[] _OwnArea;
        private Cat[] _OwnCat;
        private Role _OwnRole;
        private CISLib.Province[] _Province;
        private CISLib.SysUser _SysUser = null;

        public UserPrincipal(CISLib.SysUser sysUser, IIdentity identity)
        {
            this._SysUser = sysUser;
            this._Identity = identity;
            this.Init();
        }

        private void Init()
        {
            this._Province = ManageProvince.GetProvinceAryViaUserId(this._SysUser.UserId);
            this._OwnCat = ManageCAT.GetCATAryViaId(this._SysUser.UserId);
            this._OwnArea = ManageArea.GetAreaAryViaId(this._SysUser.UserId);
            this._OwnRole = ManageRole.GetRoleViaId(this._SysUser.RoleId);
        }

        public bool IsInRole(string role)
        {
            try
            {
                return true;
            }
            catch
            {
                return false;
            }
        }

        public IIdentity Identity
        {
            get
            {
                return this._Identity;
            }
        }

        public Area[] OwnArea
        {
            get
            {
                return this._OwnArea;
            }
            set
            {
                this._OwnArea = value;
            }
        }

        public Cat[] OwnCat
        {
            get
            {
                return this._OwnCat;
            }
        }

        public Role OwnRole
        {
            get
            {
                return this._OwnRole;
            }
            set
            {
                this._OwnRole = value;
            }
        }

        public CISLib.Province[] Province
        {
            get
            {
                return this._Province;
            }
        }

        public CISLib.SysUser SysUser
        {
            get
            {
                return this._SysUser;
            }
        }

        
    }
}

